home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00022_Script_Anima Sprite c- Subliminar < prev    next >
Text File  |  1999-03-19  |  5KB  |  155 lines

  1. property spr
  2. property memberPrim, memberUlt -- Cast members que serao animados
  3. property memPrim, memQuantos -- Membros: em numero
  4. property espera -- Tempo de espera entre cada mudanca (em ticks) 
  5. property aleatorio -- True para mudanca aleatoria
  6. property ultimaTroca -- Hora em que foi feita ultima troca
  7. property fotoAtual
  8. property tempoAleatorio
  9. property proxEspera
  10. property delta
  11. property prioridade
  12. property subliminar, memSubliminar
  13. property tempoSubliminar, deltaSubliminar
  14. property inicioTimer, estadoSub
  15.  
  16. on getBehaviorDescription
  17.   return "Anima sprites"
  18. end
  19.  
  20. on getPropertyDescriptionList
  21.   set p_list = [ ¼
  22.     #memberPrim: [ #comment:   "Primeiro membro da animacao", ¼
  23.                     #format:   #string, ¼
  24.                    #default:   "" ], ¼
  25.     #memberUlt: [ #comment:   "Ultimo membro da animacao", ¼
  26.                     #format:   #string, ¼
  27.                    #default:   "" ], ¼
  28.     #espera: [ #comment: "Espera entre cada troca em 1/60s (velocidade)",¼
  29.                       #format: #integer,¼
  30.                      #default: 60 ],¼
  31.     #aleatorio: [ #comment: "Animacao randomica",¼
  32.                       #format: #boolean,¼
  33.                      #default: false ],¼
  34.     #tempoAleatorio: [ #comment: "Tempo de animacao randomica",¼
  35.                       #format: #boolean,¼
  36.                      #default: false ],¼
  37.     #delta: [ #comment: "Espera no inicio da animacao",¼
  38.                       #format: #integer,¼
  39.                      #default: 0 ],¼
  40.     #prioridade: [ #comment: "Prioridade da animacao (se anima em momentos criticos)",¼
  41.                       #format: #integer,¼
  42.                      #default: 0 ],¼
  43.     #subliminar: [ #comment:   "Foto subliminar", ¼
  44.                     #format:   #string, ¼
  45.                    #default:   "" ], ¼
  46.     #tempoSubliminar: [ #comment: "Tempo que leva para imagem subliminar aparecer toda",¼
  47.                       #format: #integer,¼
  48.                      #default: 0 ],¼
  49.     #deltaSubliminar: [ #comment: "Tempo antes da imagem subliminar comecar a aparecer",¼
  50.                       #format: #integer,¼
  51.                      #default: 0 ]¼
  52.   ]
  53.   return p_list
  54. end
  55.  
  56. on beginSprite me
  57.   set spr = the spriteNum of me
  58.   inicializaAnima me
  59.   if prioridade < 0 then
  60.     set prioridade = 0
  61.   end if
  62. end
  63.  
  64. on inicializaAnima me
  65.   set memPrim to the number of member memberPrim
  66.   set memQuantos to (the number of member memberUlt) - memPrim + 1
  67.   set memSubliminar to the number of member subliminar
  68.   set proxEspera = random(espera)
  69.   put 0 into fotoAtual
  70.   set ultimaTroca = 0
  71.   if delta > 0 then set the visibility of sprite spr to false
  72.   set estadoSub = 4
  73. end
  74.  
  75. on cleanSprite me
  76.   puppetSprite (the spriteNum of me),false
  77.   set the visibility of sprite spr to true
  78. end 
  79.  
  80. on idleSprite me
  81.   global gMustUpdate
  82.   if ultimaTroca = 0 then 
  83.     set ultimaTroca = the timer
  84.     set inicioTimer = the timer
  85.   end if
  86.   
  87.   set tmp = the timer - ultimaTroca
  88.   if delta > 0 and tmp > delta then
  89.     set ultimaTroca = the timer
  90.     set the visibility of sprite spr to true
  91.     set delta = 0
  92.     set tmp = 0
  93.     set inicioTimer = the timer
  94.   end if
  95.   
  96.   -- Testa se ja e' hora de trocar figura
  97.   if tempoAleatorio then
  98.     if tmp > proxEspera then
  99.       set tmp = true
  100.       set proxEspera = random(espera)
  101.     else
  102.       set tmp = false
  103.     end if
  104.   else
  105.     if tmp > espera then
  106.       set tmp = true
  107.     else
  108.       set tmp = false
  109.     end if
  110.   end if
  111.   
  112.   -- Troca, se ja' for hora e se nao for em area critica
  113.   global gCritico
  114.   if tmp and prioridade >= gCritico then
  115.     
  116.     -- Descobre qual a proxima figura a trocar
  117.     if estadoSub = 0 then
  118.       set chance = (the timer - inicioTimer) * 1000 / tempoSubliminar
  119.     else if estadoSub = 1 then
  120.       set chance = 1001
  121.     else if estadoSub = 2 then
  122.       set chance = 1000 -(the timer - inicioTimer) * 1000 / tempoSubliminar
  123.     else if estadoSub = 4 and (the timer - inicioTimer) > deltaSubliminar then
  124.       set estadoSub = 0
  125.       set inicioTimer = the timer
  126.     end if
  127.     
  128.     if estadoSub < 3 and random(1000) < chance then
  129.       if estadoSub = 0 and chance > 1000 then 
  130.         set estadoSub = 1
  131.         set inicioTimer = the timer
  132.       else if estadoSub = 1 and the timer - inicioTimer > 180 then
  133.         set estadoSub = 2
  134.         set inicioTimer = the timer
  135.       else if estadoSub = 2 and chance < 0 then
  136.         set estadoSub = 4
  137.       end if
  138.       set tmp = memSubliminar
  139.     else if (aleatorio) then
  140.       put random(memQuantos - 1) - 1 into tmp
  141.       if tmp >= fotoAtual then put 1 + tmp into tmp
  142.       put tmp into fotoAtual
  143.       set tmp = memPrim + fotoAtual
  144.     else
  145.       put fotoAtual + 1 into fotoAtual
  146.       if fotoAtual >= memQuantos then put 0 into fotoAtual
  147.       set tmp = memPrim + fotoAtual
  148.     end if
  149.     
  150.     -- Muda figura e updateStage
  151.     set the member of sprite (the spriteNum of me) to tmp
  152.     set gMustUpdate to true
  153.     put the timer into ultimaTroca
  154.   end if
  155. end